<?php

class FlagControl extends Control {

    function index() {
        $db  = M("flag");
        $total = $db->count(); //获得总条数
        $page=new page($total,"10",3,1);
        $data=$db->order("fid desc")->findall($page->limit());
        $page=$page->show();
        $this->assign("page",$page);
        $this->assign("data",$data);
        $this->display();
    }
    //添加属性
    function addshow(){
        $this->display();
    }

    //修改属性
    function editshow(){
        C("debug",1);
        if ($fid = $this->_get("fid")) {
            $db = M('flag');
            $field = $db->find($fid); //获得编辑文章的原数据
            $this->assign("field", $field);
            $this->display();
        }
    }

       //修改提交上来的数据
    function editflg(){
         C("debug",1);
        $db = M("flag");
        if($db->save()){
            go('index');
        }else{
            $this->error("属性修改失败");
        }
    }
    //数据库新增属性
    function add(){
//        $flgname = $this->_post("flgname");
        $db = M("flag");
        if($db->add()){
            go('index');
        }else{
            $this->error("属性添加失败");
        }
    }


    //删除属性
    function delflag() {
        $fid = $this->_get("fid");
        if ($fid) {
            $db = M("flag");
            $data = array(); //返回客户端的数据
            if ($db->find("fid=" . $fid)) {
                $db->del($fid);  
                $data['stat'] = "success";
                $data['msg'] = "";
            } else {
                $data['stat'] = "error";
                $data['msg'] = "删除文章失败,请重试";
            }
            echo json_encode($data);exit;
        }
    }


    //底部删除按钮
    function delall() {
        $c=isset($_GET['fid'])?1:0;
        $fid = $this->_get("fid");
        $fid = explode(',', $fid);
        // $data['msg'] = var_dump($aid);
        // echo json_encode($data);exit;
        if ($c) {
            // $data['msg'] = $aid;
            // echo json_encode($data);exit;
            $data = array(); //返回客户端的数据
            foreach ($fid as $v) {
                $db = M("flag");
                if ($db->find("fid=" . $v)) {
                    $db->del($v);  
                    $data['stat'] = "success";
                    $data['msg'] = "";
                }else {
                    $data['stat'] = "error";
                    $data['msg'] = "删除文章失败,请重试";
                }
            }
            echo json_encode($data);exit;
        }
    }


























}

?>
